home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 24 / Amiga Format AFCD24 (Feb 1998, Issue 108).iso / -in_the_mag- / emulation / amiga / uae-0.7.0b2 / src / od-amiga / ami-appw.c next >
C/C++ Source or Header  |  1998-01-20  |  3KB  |  125 lines

  1.  /* 
  2.   * UAE - The Un*x Amiga Emulator
  3.   * 
  4.   * AppWindow interface
  5.   * 
  6.   * Copyright 1997 Samuel Devulder.
  7.   */
  8.  
  9. /****************************************************************************/
  10.  
  11. #include <workbench/startup.h>
  12.  
  13. #include <exec/execbase.h>
  14. #include <exec/memory.h>
  15.  
  16. #include <dos/dos.h>
  17.  
  18. #include <proto/intuition.h>
  19. #include <proto/exec.h>
  20. #include <proto/dos.h>
  21. #include <proto/wb.h>
  22.  
  23. /****************************************************************************/
  24.  
  25. #include "sysconfig.h"
  26. #include "sysdeps.h"
  27. #include "options.h"
  28. #include "uaeexe.h"
  29.  
  30. /****************************************************************************/
  31.  
  32. #define LEN 256
  33.  
  34. struct Library          *WorkbenchBase;
  35.  
  36. static struct AppWindow *AppWin;
  37. static struct MsgPort   *AppPort;
  38.  
  39. int  appw_init(struct Window *W);
  40. void appw_exit(void);
  41. void appw_events(void);
  42.  
  43. /****************************************************************************/
  44.  
  45. int appw_init(struct Window *W)
  46. {
  47.     WorkbenchBase = (void*)OpenLibrary("workbench.library",36L);
  48.     if(WorkbenchBase) {
  49.         AppPort = CreatePort(0,0);
  50.         if(AppPort) {
  51.             AppWin = AddAppWindow(0,0,W,AppPort,NULL);
  52.             if(AppWin) {
  53.                 write_log("AppWindow started.\n");
  54.                 return 1;
  55.             }
  56.         }
  57.     }
  58.     write_log("Failed to start AppWindow.\n");
  59.  
  60.     return 0;
  61. }
  62.  
  63. /****************************************************************************/
  64.  
  65. void appw_exit(void)
  66. {
  67.     if(AppPort) {
  68.         void *msg;
  69.         while((msg=GetMsg(AppPort))) ReplyMsg(msg);
  70.         DeletePort(AppPort);
  71.         AppPort = NULL;
  72.     }
  73.     if(AppWin) {
  74.         RemoveAppWindow(AppWin);
  75.         AppWin = NULL;
  76.     }
  77.     if(WorkbenchBase) {
  78.         CloseLibrary((void*)WorkbenchBase);
  79.         WorkbenchBase = NULL;
  80.     }
  81. }
  82.  
  83. /***************************************************************************/
  84.  
  85. static void addcmd(char *cmd, int len, ULONG lock, char *name)
  86. {
  87.     len -= strlen(cmd); if(len<=0) return; while(*cmd) ++cmd;
  88.  
  89.     *cmd++ = ' '; if(--len<=0) return;
  90.  
  91.     NameFromLock(lock,cmd,len);
  92.     len -= strlen(cmd);if(len<=0) return;while(*cmd) ++cmd;
  93.     if(cmd[-1]!=':') {*cmd++='/'; len -= 1;if(len<=0) return;}
  94.     strncpy(cmd,name,len);
  95.     while(*cmd) {++cmd; if(--len<=0) *cmd='\0';}
  96. }
  97.  
  98. /***************************************************************************/
  99.  
  100. void appw_events(void)
  101. {
  102.     if(AppWin) {
  103.         struct AppMessage *msg;
  104.         struct WBArg *arg;
  105.         while((msg=(void*)GetMsg(AppPort))) {
  106.             char cmd[LEN];
  107.             int  i;
  108.  
  109.             arg = msg->am_ArgList;
  110.  
  111.             strcpy(cmd,"cd ");
  112.             NameFromLock(arg[0].wa_Lock,&cmd[3],LEN-3);
  113.             if(!uaeexe(cmd)) {
  114.            strcpy(cmd,"run ");strcpy(cmd+4,arg[0].wa_Name);
  115.                for(i=1;i<msg->am_NumArgs;++i)
  116.                    addcmd(cmd,LEN-2,arg[i].wa_Lock,arg[i].wa_Name);
  117.                    /*             ^        */
  118.                    /* 2 bytes for security */
  119.                uaeexe(cmd);
  120.             }
  121.             ReplyMsg((void*)msg);
  122.         }
  123.     }
  124. }
  125.